#include "WebDirectionLogic.h"
#include <string>

void DirectionLogic::calculateWheelSpeeds(DirectionCode dir_code, int target_speed, int& left_speed, int& right_speed) {
    left_speed = 0;
    right_speed = 0;

    switch (dir_code) {
        case DirectionCode::STOP:
            left_speed = 0;
            right_speed = 0;
            break;
        case DirectionCode::FORWARD: // 前进-直行
            left_speed = target_speed;
            right_speed = target_speed;
            break;
        case DirectionCode::BACKWARD: // 后退-直行
            left_speed = target_speed;
            right_speed = target_speed;
            break;
        case DirectionCode::LEFT_FRONT: // 左前-左轮减速
            left_speed = static_cast<int>(target_speed * 0.5);
            right_speed = target_speed;
            break;
        case DirectionCode::RIGHT_FRONT: // 右前-右轮减速
            left_speed = target_speed;
            right_speed = static_cast<int>(target_speed * 0.5);
            break;
        case DirectionCode::LEFT_BACK: // 左后-左轮减速
            left_speed = static_cast<int>(target_speed * 0.5);
            right_speed = target_speed;
            break;
        case DirectionCode::RIGHT_BACK: // 右后-右轮减速
            left_speed = target_speed;
            right_speed = static_cast<int>(target_speed * 0.5);
            break;
        default:
            left_speed = 0;
            right_speed = 0;
            break;
    }
}

std::string DirectionLogic::getDirectionName(DirectionCode dir_code) {
    switch (dir_code) {
        case DirectionCode::STOP: return "停止";
        case DirectionCode::FORWARD: return "前进";
        case DirectionCode::BACKWARD: return "后退";
        case DirectionCode::LEFT_FRONT: return "左前";
        case DirectionCode::RIGHT_FRONT: return "右前";
        case DirectionCode::LEFT_BACK: return "左后";
        case DirectionCode::RIGHT_BACK: return "右后";
        default: return "未知方向";
    }
}

std::string DirectionLogic::getDetailedDirection(DirectionCode dir_code, int left_speed, int right_speed) {
    std::string base_info = "（左轮：" + std::to_string(left_speed) + " | 右轮：" + std::to_string(right_speed) + "）";
    switch (dir_code) {
        case DirectionCode::STOP: return "停止" + base_info;
        case DirectionCode::FORWARD: return "前进-直行" + base_info;
        case DirectionCode::BACKWARD: return "后退-直行" + base_info;
        case DirectionCode::LEFT_FRONT: return "左前-内侧减速" + base_info;
        case DirectionCode::RIGHT_FRONT: return "右前-内侧减速" + base_info;
        case DirectionCode::LEFT_BACK: return "左后-内侧减速" + base_info;
        case DirectionCode::RIGHT_BACK: return "右后-内侧减速" + base_info;
        default: return "未知方向" + base_info;
    }
}